package com.jdk.demo.nio.networkinterface;

import java.net.InetAddress;
import java.net.UnknownHostException;

public class InetAddressDemo {

	public static void main(String[] args) throws UnknownHostException {
		// 返回本地主机ip地址信息，如果本机拥有多个ip，则只返回下标为0的第一个ip
		InetAddress localhost = InetAddress.getLocalHost();
		System.out.println("localhost.getAddress()地址为=");
		byte[] localIPAddress = localhost.getAddress();
		for (int i = 0; i < localIPAddress.length; i++) {
			System.out.print(" " + localIPAddress[i] + " ");
		}
		System.out.println();
		System.out.println("  " + localhost.getClass().getName());
		System.out.println();
		System.out.println("loopbackAddress.getAddress()地址为=");
		InetAddress loopbackAddress = InetAddress.getLoopbackAddress();
		byte[] loopbackIPAddress = loopbackAddress.getAddress();
		for (int i = 0; i < loopbackIPAddress.length; i++) {
			System.out.print(" " + loopbackIPAddress[i] + " ");
		}
		System.out.println();
		System.out.println("  " + localhost.getClass().getName());
	}

}
